let search = document.getElementById("search");
let searchList = document.getElementById("searchList");

function handlerJsonpResponse(data) {
    console.log(data.g);
    if (data.g === undefined) {
        searchList.innerHTML = "";
    } else {
        searchList.innerHTML = data.g.map(item => `<li>${item.q}</li>`).join("");
    }
};
function sendJsonpRequest() {
    let script = document.createElement("script");
    let url = `https://www.baidu.com/sugrec?prod=pc&from=pc_web&wd=${search.value}&cb=handlerJsonpResponse`;
    script.src = url;
    document.body.appendChild(script);
    document.body.removeChild(script);
};
search.addEventListener("input", sendJsonpRequest);